﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Core.Objects;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common;
using Northwind.Domain;

namespace Ex01
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。

        static void Main()
        {
            var db = new NorthwindEntities();



            Customer cust = db.Customers.Single(c => c.ID == 1);
            // Inserts the two purchases  to cust
            Purchase p1 = new Purchase { ID = 100, Description = "Bike", Price = 500, Date = DateTime.Now };
            Purchase p2 = new Purchase { ID = 101, Description = "Tools", Price = 100, Date = DateTime.Now };
            cust.Purchases.Add(p1);
            cust.Purchases.Add(p2);
            db.SaveChanges();
            //cust.Purchases.AsEnumerable().Dump("cust's purchases, including the two new ones we just inserted");

            // Delets the two purchases  from cust
            var cust2 = db.Customers.Single(c=>c.ID==1);
            db.Purchases.Remove(new Purchase {ID = 100});
            db.Purchases.Remove(new Purchase {ID = 101});
            db.SaveChanges();
            cust2.Purchases.AsEnumerable().Dump();

            Console.ReadKey();
        }
    }
}
